package com.riadeveloper.store
{
	import com.riadeveloper.UI.Holder;

	public class DataStore
	{
		private static var instance:DataStore;
		private  var _holderArr:Array = new Array;
		
		public function get holderArr():Array
		{
			return _holderArr;
		}
		
		public function  addToHolderArr(mc:Holder):void
		{
			_holderArr.push(mc);

			for(var i:int = 1 ; i<_holderArr.length; i++)
			{
				
				 if(_holderArr[i-1].y > _holderArr[i].y)
				 {
					 var _holder:Holder = _holderArr[i-1];
					 _holderArr[i-1] = _holderArr[i];
					 _holderArr[i] =  _holder;
				 }
				 if(_holderArr[i-1].y == _holderArr[i].y)
				 {
					 if(_holderArr[i-1].x >_holderArr[i].x)
					 {
						 _holder = _holderArr[i-1];
						 _holderArr[i-1] = _holderArr[i];
						 _holderArr[i] =  _holder;
					 }
				 }
				 
			}
			 
		}


		public static function getInstance():DataStore {
			if (instance == null) {
				instance = new DataStore(new SingletonBlocker());
			}
			return instance;
		}
		
		public function DataStore(p_key:SingletonBlocker):void {
			
			if (p_key == null) {
				throw new Error("Error: Instantiation failed: Use DataStore.getInstance() instead of new.");
			}
		}	
		
	}
}
internal class SingletonBlocker {}